package com.ctgu.frequence.step4;


import com.ctgu.frequence.step1.CountWord;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class VerbUnite {
    private static byte[] bytes = new byte[1024];

    public static String uniteVerb(String str, File file) throws IOException {
        String[] list = str.split("\\W+");
        Map<String,String> map = new HashMap<>();
        //读取动词归一表
        FileInputStream in = new FileInputStream(file);
        InputStreamReader reader = new InputStreamReader(in);
        BufferedReader br = new BufferedReader(reader);
        String line = "";
        while((line = br.readLine()) != null){
            line = line.trim();
            String[] verbs = line.split(" ");
            //建立各种形态到动词原型的映射
            for(int i = 1; i < verbs.length; i++){
                map.put(verbs[i],verbs[0]);
            }
        }
        br.close();
        reader.close();
        in.close();
        //替换动词原形
        StringBuffer sb = new StringBuffer();
        for(int i = 0; i < list.length; i++){
           if(map.containsKey(list[i])){
               sb.append(map.get(list[i]) + " ");
           }else{
               sb.append(list[i] + " ");
           }
       }
        String s = sb.toString();
        return s;
    }
}
